﻿using AutoMapper;
using MultipleDB.Entitys;
using PineLake.Entitys.Dto;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PineLake.Mapping
{
    /// <summary>
    /// 实体自动映射配置类
    /// </summary>
    public class AutoMapperConfig : Profile
    {
        public AutoMapperConfig()
        {

            //#region (Products) 产品
            //CreateMap<Products, Add_Products_Dto>().ReverseMap();   //添加
            //CreateMap<Products, Modify_Products_Dto>().ReverseMap();   //修改
            //#endregion
            #region 通用格式化
            ////日期转换格式(20230101 转换成 2023-01-01)
            //CreateMap<string, DateTime>().ConvertUsing<GenderTypeConvertert>();
            #endregion
            #region (AccountInfo) 
            CreateMap<AccountInfo, Add_AccountInfo_Dto>().ReverseMap();   //添加
            CreateMap<AccountInfo, Modify_AccountInfo_Dto>().ReverseMap();   //修改
            #endregion
        }
    }
    /// <summary>
    /// 日期转换格式(20230101 转换成 2023-01-01)
    /// </summary>
    public class GenderTypeConvertert : ITypeConverter<string, DateTime>
    {
        public DateTime Convert(string Source, DateTime DateTimes, ResolutionContext context)
        {
            DateTimes = DateTime.ParseExact(Source, "yyyyMMdd", CultureInfo.CurrentCulture);
            return DateTimes;
        }
    }
}
